<?php
namespace app\home\model;

use think\Model;

class Comment extends Model {
    public function index()
    {
        # code...
    }
    public function user()
    {
        # code...
        return $this->belongsTo('user', 'userid', 'id')->field('username,avatar,id,title,sex,staus');
    }
    public function reply()
    {
        # code...
        return $this->hasMany('reply','cid','id');
    }
    public function send($data)
    {
        # code...
        $validate = new \app\home\validate\Comment();
        if (!$validate->scene('comment')->check($data)) {
            return $validate->getError();
        } 
        $result = $this->save($data);
        if ($result) {
            return 1;
        }else {
            return '评论失败！';
        }
    }
}